import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
const state = {
  count:0,
  username:'xxx'
}
const mutations = {
  add(){
    state.count++;
  },
  jian(){
    state.count--;
  }
}
const actions = {
  kongzhi({commit}){
    if(this.state.count == this.getters.nums){
      window.alert('增长到了:'+5);
      return false;
    }
    return commit('add');
  }
}
const getters = {
  nums(state){
    // return state.count % 2 === 0 ? 'even' : 'odd'
    return 5;
  }
}
export default new Vuex.Store({
  state,
  getters,
  actions,
  mutations
})
